<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->


<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="DC.Type" content="topic">
<meta name="DC.Title" content="MySQL Database">
<meta name="product" content="">
<meta name="DC.Relation" scheme="URI" content="en-us_topic_0000001839267033.html">
<meta name="prodname" content="">
<meta name="version" content="">
<meta name="brand" content="30-OceanProtect Appliance 1.5.0-1.6.0 Help Center">
<meta name="DC.Publisher" content="20240608">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="EN-US_TOPIC_0000001792387956">
<meta name="DC.Language" content="en-us">
<link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
<title>MySQL Database</title>
</head>
<body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px"><a name="EN-US_TOPIC_0000001792387956"></a><a name="EN-US_TOPIC_0000001792387956"></a>

<h1 class="topictitle1">MySQL Database</h1>
<div><div class="section" id="EN-US_TOPIC_0000001792387956__section136297539915"><a name="EN-US_TOPIC_0000001792387956__section136297539915"></a><a name="section136297539915"></a><h4 class="sectiontitle">pre-freeze-script Script</h4><p>The script content is as follows:</p>
<p>In the script, <strong>MYSQL_USER</strong> is a MySQL database user. The default user is <strong>root</strong>.</p>
<p><strong>MYSQL_PASSWORD</strong> is the password of the database user.</p>
<pre class="screen">#!/bin/sh
FREEZEFILE="/scripts/mysql-pre-freeze.tmp"
FREEZELOG="/scripts/mysql-pre-freeze.log"
date &gt;&gt; ${FREEZELOG}
echo -e "\n attempting to run pre-freeze script for MySQL as root user\n" &gt;&gt; ${FREEZELOG}
if [ "$(id -u)" -eq "0" ]; then 
    mysql -u<strong><em>MYSQL_USER</em></strong> -p<strong><em>MYSQL_PASSWORD</em></strong> -e "show processlist;" &gt;&gt; "${FREEZEFILE}" 2&gt;&amp;1
    if [ $? -ne 0 ]
    then
        [ -f ${FREEZEFILE} ] &amp;&amp; rm -rf ${FREEZEFILE}
        echo "[ERROR]:Show process list failed." &gt;&gt; ${FREEZELOG}
    fi
 
    echo "flush tables with read lock;select 1 and sleep(60);" | mysql -u$MYSQL_USER -p$MYSQL_PASSWORD &amp; &gt;&gt; "${LOG_FILE_NAME}" 2&gt;&amp;1
    if [ $? -ne 0 ]
    then
        [ -f ${TEMP_FILE_NAME} ] &amp;&amp; rm -rf ${TEMP_FILE_NAME}
        echo "[ERROR]:Freeze mysql failed" &gt;&gt; ${FREEZELOG}
    fi   
    echo "[INFO]:Freeze mysql success." &gt;&gt; ${FREEZELOG}
    done 
fi </pre>
</div>
<div class="section" id="EN-US_TOPIC_0000001792387956__section136695016107"><a name="EN-US_TOPIC_0000001792387956__section136695016107"></a><a name="section136695016107"></a><h4 class="sectiontitle">post-thaw-script Script</h4><p>The script content is as follows:</p>
<p><strong>MYSQL_USER</strong> is a MySQL database user. The default user is <strong>root</strong>.</p>
<p><strong>MYSQL_PASSWORD</strong> is the password of the database user.</p>
<pre class="screen">#!/bin/sh
UNFREEZEFILE="/scripts/mysql-post-thaw.tmp"
UNFREEZELOG="/scripts/mysql-post-thaw.log"
date &gt;&gt; ${UNFREEZELOG} 
echo -e "\n attempting to run post-thaw script for MySQL as root user\n" &gt;&gt; ${UNFREEZELOG}
if [ "$(id -u)" -eq "0" ]; then 
    mysql -u<strong><em>MYSQL_USER</em></strong> -p<strong><em>MYSQL_PASSWORD</em></strong> -e "show processlist;" &gt;&gt; "${UNFREEZEFILE}" 2&gt;&amp;1
    if [ $? -ne 0 ]
    then
        [ -f ${UNFREEZEFILE} ] &amp;&amp; rm -rf ${UNFREEZEFILE}
        echo "[ERROR]:Show process list failed." &gt;&gt; ${UNFREEZELOG}
    fi
 
    cat ${TEMP_FILE_NAME} | grep "select 1 and sleep(60)" | awk -F " " '{print $1}'| while read pid
    mysql -uMYSQL_USER -pMYSQL_PASSWORD -e "kill $pid;" &gt;&gt; "${LOG_FILE_NAME}" 2&gt;&amp;1
    if [ $? -ne 0 ]
    then
        [ -f ${TEMP_FILE_NAME} ] &amp;&amp; rm -rf ${TEMP_FILE_NAME}
        echo "[ERROR]:Thaw mysql failed.PIDs is ${pid}" &gt;&gt; ${UNFREEZELOG}
    fi   
    echo "[INFO]:Stop sql process ${pid} success." &gt;&gt; ${UNFREEZELOG}
    done 
fi</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="en-us_topic_0000001839267033.html">Step 3: Configuring the Application-Consistent Backup Script</a></div>
</div>
</div>

<div class="hrcopyright"><hr size="2"></div><div class="hwcopyright">Copyright &copy; Huawei Technologies Co., Ltd.</div></body>
</html>